package cn.edu.zjicm.wordsnet_d.adapter;

import java.util.List;

import cn.edu.zjicm.wordsnet_d.R;
import cn.edu.zjicm.wordsnet_d.pay.Product;
import cn.edu.zjicm.wordsnet_d.util.NightModeUtil;
import cn.edu.zjicm.wordsnet_d.util.Utils;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.RelativeLayout.LayoutParams;

public class RechargeAdapter extends BaseAdapter {

	Context mContext;
	List<Product> productList;

	public RechargeAdapter(List<Product> productList, Context mContext) {
		this.productList = productList;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		return productList.size();
	}

	@Override
	public Object getItem(int position) {
		return productList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	private int clickTemp = -1;

	public void setSelection(int position) {
		clickTemp = position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = LayoutInflater.from(mContext).inflate(R.layout.view_add_school_item, null);
		RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.add_school_item_layout);
		ImageView iv = (ImageView) view.findViewById(R.id.iv);
		TextView nameTv = (TextView) view.findViewById(R.id.add_school_item_name);
		TextView divider = (TextView) view.findViewById(R.id.add_school_divider);
		if (NightModeUtil.isNightModeNow())
			divider.setVisibility(View.GONE);
		else
			divider.setVisibility(View.VISIBLE);

		if (clickTemp == position) {
			layout.setBackgroundColor(mContext.getResources().getColor(R.color.tab_indicator_text_bg_down));
			iv.setBackgroundResource(R.drawable.white_tick);
			iv.setVisibility(View.VISIBLE);
			nameTv.setTextColor(Color.WHITE);
		}

		Product product = productList.get(position);
		nameTv.setText(product.getProductName() + " = " + product.getPrice() + "元");
		return view;
	}

}
